var footer=$('#footer').removeAttr('id').clone();var headpic=$('.head_pic').eq(0).clone();$('body').on('pagecreate','.ui-page',function(){if((!supportEmoji)&&(typeof twemoji!='undefined')){twemoji.size='16x16'
twemoji.parse(this,{callback:function(icon,options,variant){switch(icon){case'a9':case'ae':case'2122':return false;}
return''.concat(options.base,options.size,'/',icon,options.ext);}});}
var temp=$(this);var header=temp.children('[data-role="header"]')
if(temp.find('footer').length==0){temp.append(footer.clone());}
if(headpic.length&&temp.find('.head_pic').length==0){console.info(this)
temp1=temp
header.after(headpic.clone());}
$('.youku').load(function(){$(this).height($(this).width()*0.8);})
if(ifwxsuccess){$('.chooseimages, #fwscan').removeClass('ui-disabled');}
temp.find('.decimgsrc').load(function(){var self=$(this)
var imgdec=self.prev('.imgdec')
if(imgdec.text()==""){imgdec.hide()}else{imgdec.css('max-width',this.width-2+'px')}})})
var wx_logo_bak,wx_logo_url=$('#wx_logo img').attr('src');$('body').on('pageshow','.ui-page',function(){var wx_logo=$(this).find('.wx_logo');if(wx_logo.length!=0){wx_logo_bak=$('#wx_logo').html()
wx_logo_url=wx_logo.find('img').attr('src')
$('#wx_logo').html(wx_logo.html())}else{wx_logo_url=$('#wx_logo img').attr('src');}
if(inwx&&wxready){refreshwechat(this);}})
$('body').on('pagebeforeshow','.ui-page',function(){})
$('body').on('pagehide','.ui-page',function(){})
$('body').on('pagebeforecreate','[data-role=page]',function(){if(inwx&&wxready&&this.hasAttribute('wechatsignused')){fixpage(this);}
$('img.decimgsrc').load(function(){self=$(this)
selfcopy=self.clone()
selfcopy.removeClass('style')
w=selfcopy[0].width,h=selfcopy[0].height
console.info('load:',w+'x'+h)
self.attr('img-size',w+'x'+h)
selfcopy.remove()})
$('#map iframe').load(function(){$(this).show()
$.mobile.loading('hide')
$(this).height($('footer').offset().top-$(this).offset().top)
$(this).width($(this).parent().width())})
$('#fwquery iframe').load(function(){$(this).show()
$.mobile.loading('hide')
$(this).height($('#fwquery footer').offset().top-$(this).offset().top)
$(this).width($(this).parent().width())})
var fwvalue=$('#fwcode').val()
$('#fwcode').mask('9999-9999-9999-9999')
if(fwvalue){newfwvalue=''
var i
for(i=0;i<3;i++){newfwvalue+=fwvalue.slice(i*4,i*4+4)+'-'}
newfwvalue+=fwvalue.slice(i*4,i*4+4)
$('#fwcode').val(newfwvalue)}})
$('body').on('pagebeforehide','.ui-page',function(){var wx_logo=$(this).find('.wx_logo');if(wx_logo.length!=0&&wx_logo_bak!=null){$('#wx_logo').html(wx_logo_bak)}})
if(!$('#home').length){$('[data-role="page"]:not([id="home"], [id="postsid"])').eq(0).find('header').append('<a href="." rel="external" class="ui-btn-left" data-icon="home" data-iconpos="notext">Home</a>');}
$('#postsid header').append('<a href="memberposts" class="ui-btn-left" rel="external" data-role="button" data-icon="back" class="ui-btn-right">分享区</a>')
var images1=['http://ss.bdimg.com/static/superman/img/logo/bd_logo1_31bdc765.png','http://img5.imgtn.bdimg.com/it/u=3750695734,1192334129&fm=21&gp=0.jpg','http://img5.imgtn.bdimg.com/it/u=3750695734,1192334129&fm=21&gp=0.jpg','http://img5.imgtn.bdimg.com/it/u=3750695734,1192334129&fm=21&gp=0.jpg','http://img5.imgtn.bdimg.com/it/u=3750695734,1192334129&fm=21&gp=0.jpg','http://img0.imgtn.bdimg.com/it/u=751865090,564508156&fm=21&gp=0.jpg']
var images={localId:[],};var imgdec
addpreimage=function(items){var $div=$('.imagespreview')
for(i=0;i<items.length;i++){var picpre=$('<div class="picpre"><img src="'
+items[i]+
'"><div class="addimgdec"></div><br/>'+
'<a href="#" class="delete">删除</a> '+
'<a href="#" class="adddes">描述</a></img></div>')
$div.append(picpre);picpre.find('.delete').bind('click',function(){var parent=$(this).parent();images.localId.splice(parent.index(),1);parent.remove();})
picpre.find('.adddes').bind('click',function(){imgdec=$(this).siblings('.addimgdec')
imgdesdialog(this,imgdec)})}}
$('body').on('click','.chooseimages',function(){chooseimage(images,addpreimage);})
$('body').on('change','#title',function(event,ui){if($(this).val()!=""){$('[type=submit]').button('enable');}else{$('[type=submit]').button('disable');}});chooseimage=function(items,handle){$.mobile.loading('show');wx.chooseImage({count:9,sizeType:['original','compressed'],sourceType:['album','camera'],success:function(res){items.localId=items.localId.concat(res.localIds)
handle(res.localIds);$.mobile.loading('hide');$('.chooseimages .ui-btn-text').text('继续选择');},cancel:function(){$.mobile.loading('hide');}});}
uploadimage=function(items){if(items.localId.length==0){mydialog($('input[type=submit]'),'请选择图片后再上传!');return;}
var i=0,length=items.localId.length
var serverIds=[];upload=function(){wx.uploadImage({localId:items.localId[i],success:function(res){$('.delete').eq(i).text('上传成功').unbind('click');i++;serverIds.push(res.serverId);if(i<length){upload();}else{$.mobile.loading('show');submitpost(serverIds);}}})}
upload();}
$('body').on('click','#submit',function(){var imagesids=uploadimage(images);return false;})
submitpost=function(imageids){imgdecs=$('.addimgdec').map(function(){return $(this).text()}).get();imgdecs=escape(JSON.stringify(imgdecs).replace(/%u/g,'%25u'))
$.post('postweb',$('form').serialize()+'&imageids='+imageids+'&imgdecs='+imgdecs,function(data){$.mobile.loading('hide');if(data=='done'){mydialog($('input[type=submit]'),'上传成功',function(){window.location.replace('memberposts')});}else if(data=='postalready'){mymessage('抱歉,活动投票类型仅可发布一次')}else if(data=='VoteEnd'){mymessage('本投票活动已经结束，感谢您的参与')}else if(data=='nosession'){myauthdialog($('input[type=submit]'));}else{mydialog($('input[type=submit]'),'上传失败');}})}
mymessage=function(text){$.mobile.loading('show',{'text':text,'textonly':true,'textVisible':true,'theme':'a'})
setTimeout('$.mobile.loading("hide")',1500);}
mydialog=function(element,buttonPrompt,okfunc){if(okfunc==null){okfunc=function(){};}
element.simpledialog2({mode:'button',headerText:'温馨提示',buttonPrompt:buttonPrompt,themeDialog:'c',buttons:{'确定':{click:okfunc,},}})}
myauthdialog=function(self){mydialog(self,'您还未登录<br/>按确定键返回绑定微信授权',function(){location.replace('auth2?goto=memberposts')});}
imgdesdialog=function(e,imgdec){$('body').simpledialog2({mode:'blank',headerText:'输入图片描述',buttonInput:true,headerClose:true,forceInput:false,callbackOpen:function(){$('#dsubmit').bind('click',function(){console.info($('.inputimgdes input').val())
console.info($(e).parent())
imgdec.text($('.inputimgdes input').val());})},blankContent:'<div class="inputimgdes"><input value="'+imgdec.text()+'"/>'+
'<a id="dsubmit" rel="close" href="#" data-role="button" data-icon="check">确定</a>'+
'</div>'})}
mytextdialog=function(){$('body').simpledialog2({mode:'blank',headerText:'评论内容',buttonInput:true,headerClose:true,forceInput:true,callbackOpen:function(){},blankContent:'<form class="textareacomment"><textarea name="c_content" id="comment" placeholder="评论内容"></textarea>'+
'<a class="postcomment" rel="close" href="#" data-inline="true" data-role="button" data-icon="check">确定</a>'+
'</form>'})}
$('body').on('click','.getcomment a',function(){mytextdialog();})
var supportEmoji=false,inwx=false,UA=navigator.userAgent;if(UA.match(/Mac\s+OS/i)&&!UA.match(/(Chrome|Firefox)/i)){supportEmoji=true;}
if(UA.search('MicroMessenger')!=-1){inwx=true;}
fixpage=function(self){$self=$(self);if($self.attr('data-external-page')=="true"){$self.attr('data-bak-url',$self.attr('data-url'));$self.attr('data-url','fixforwechat'+$self.attr('data-url').replace(/[\/?]/g,'&'))}}
wechatshare=function(title,imgurl,link,des){if(!des){des="音速风暴"}
var imgurl=$.mobile.path.makeUrlAbsolute(imgurl)
var link=$.mobile.path.makeUrlAbsolute(link)
wx.onMenuShareTimeline({title:title,link:link,imgUrl:imgurl,success:function(){$.post('manage?action=wxshareTimeline&link='+link)},cancel:function(){alert('朋友圈'+'分享取消')},});wx.onMenuShareAppMessage({title:title,desc:des,link:link,imgUrl:imgurl,type:'',dataUrl:'',success:function(){$.post('manage?action=wxshareAppMesage&link='+link)},cancel:function(){alert('微信朋友'+'分享取消')},});wx.onMenuShareQQ({title:title,desc:des,link:link,imgUrl:imgurl,success:function(){alert('QQ好友'+'分享成功')},cancel:function(){alert('QQ好友'+'分享取消')},});wx.onMenuShareWeibo({title:title,desc:des,link:link,imgUrl:imgurl,success:function(){alert('QQ微博'+'分享成功')},cancel:function(){alert('QQ微博'+'分享取消')},});wx.onMenuShareQZone({title:title,desc:des,link:link,imgUrl:imgurl,success:function(){alert('QQ空间'+'分享成功')},cancel:function(){alert('QQ空间'+'分享取消')},});}
var wxconfig={},wxconfigset=false,wxready=false;if($(document).find('.wx_data').length==1){$('.wx_data input').each(function(i,e){wxconfig[e.name]=e.value;})
wxconfig.debug=false;wxconfig.jsApiList=['checkJsApi','chooseImage','uploadImage','hideMenuItems','onMenuShareAppMessage','onMenuShareTimeline','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone','previewImage','scanQRCode',];wxconfigset=true}
var ifwxsuccess=false
refreshwechat=function(self){var title=$('title').text()
var imgurl=wx_logo_url;var link;if($(self).attr('data-bak-url')=='undefined'){link=location.href;}else{link=$(self).attr('data-bak-url')}
var des=$(self).attr('wx-des')
if(des){wechatshare(title,imgurl,link,des);}else{wechatshare(title,imgurl,link);}}
if(wxconfigset){wx.config(wxconfig);wx.ready(function(){wx.checkJsApi({jsApiList:['chooseImage','uploadImage','scanQRCode'],success:function(res){ifwxsuccess=true;$('.chooseimages, #fwscan').removeClass('ui-disabled');},});wxready=true;refreshwechat($('[data-role=page]')[0]);});}
$('body').on('click','.delpost,.c_delbtn',function(){self=$(this)
if(self.hasClass('c_delbtn')){btntype='评论'
clickfunc=function(){deletcomment(self)}}else{btntype='贴'
clickfunc=function(){deletpost(self)}}
self.simpledialog2({mode:'button',headerText:'温馨提示',buttonPrompt:'确认删除此'+btntype+'?<br/>点确认删'+btntype+',点其它位置取消返回',themeDialog:'c',forceInput:false,buttons:{'确定':{click:clickfunc,},}})})
deletpost=function(self){$.mobile.loading('show')
var pid=self.parent().find('.ui-link-inherit').attr('href').split('pid=')[1]
$.post('manage?action=delpost',{'pid':pid}).done(function(data){console.info(data);if(data=='delsuccess'){var parent=self.parent()
var ul=self.parents('ul')
var divider=parent.prevAll(".ui-li-divider").eq(0)
var count=parseInt(divider.children('span.ui-li-count').text())
if(count>1){divider.children('span.ui-li-count').text(--count)}else{divider.remove()}
parent.remove();ul.listview('refresh');}
$.mobile.loading('hide')})}
deletcomment=function(self){$.mobile.loading('show')
pid=self.attr('c_pid')
$.post('manage?action=delcomment',{'pid':pid}).done(function(data){console.info(data)
if(data=='delsuccess'){self.parents('.c_item').remove()}
$.mobile.loading('hide')})}
$('body').on('click','.getlike',function(e){self=$(this)
pid=self.parents('.ui-page').attr('data-bak-pid')
$.post('manage?action=getlike',{'pid':pid}).done(function(data){console.info(data);if(data=='nosession'){mymessage('未登录用户无法点赞');self.removeClass('ui-disabled')}else if(data=='nosessionOpenid'){mymessage('请从公众号进入本页面, 或在分享区登录后进入');self.removeClass('ui-disabled')}else if(data=='Done'){self.addClass('heartAnimation')
var getlikecount=parseInt(self.next().text())+1
self.parents('.ui-page').find('.likecount,.likeCount').text(getlikecount)
refreshgetlike(self,getlikecount)
}else if(data=='AlreadyLike'){mymessage('此贴您已点过赞');self.css('background-position','right')
}else if(data=='AlreadyLikeVote'){mymessage('你今日已投过票，请明天再来投票吧')
self.css('background-position','right')}else if(data=='VoteEnd'){mymessage('本投票活动已经结束，感谢您的参与')}else{mymessage('未知错误');}})
})
refreshgetlike=function(self,getlikecount){var page=self.parents('.ui-page')
var pid=page.attr('data-bak-pid')
var postscount=$('a[href$="pid='+pid+'"]').parent().find('.ui-li-count')
postscount.text(postscount.text().replace(/\d+/,getlikecount))}
getlikefunc=function(e){var x=e.pageX,y=e.pageY
var i=$('<b>').text('+1')
i.css({'top':y-20,'left':x+10,'position':'absolute'})
$('body').append(i)
i.animate({top:y-100,opacity:0,"font-size":"3em"},1000,function(){i.remove()});}
$('body').on('focus','textarea.comment',function(){self=$(this);self.next().show();})
$('body').on('click','a.cancelcomment',function(){self=$(this);t=self.parent().prev();t.val("")
self.parent().hide();})
$('body').on('click','a.postcomment',function(){var self=$(this);self.addClass('ui-disabled')
$.mobile.loading('show');form=self.parents('form')
var pid=self.parents('.ui-page').attr('data-bak-pid')
$.post('manage?action=postcomment&pid='+pid,form.serialize(),null,'json').done(function(data){$.mobile.loading('hide');console.info(data)
refreshcomment(data.comments)
$('.commentit').hide()
$('textarea.comment').val("")
self.removeClass('ui-disabled')}).fail(function(data){console.info(data.responseText);$.mobile.loading('hide');self.removeClass('ui-disabled')
if(data.responseText=='nosession'){myauthdialog(self);}else{mymessage('未知错误:'+data.responseText)}})})
refreshcomment=function(comments){var c_items=$('.c_items')
c_items.empty();for(i=0;i<comments.length;i++){c_item=getcomment(comments[i])
c_items.append(c_item)}}
getcomment=function(comment){c_item=$('<div class="c_item"><div class="author">'+
'<img src="'+comment.headimgurl+'"/><div><strong>'+comment.author+'</strong></div>'+
'</div><div class="c_item_content">'+comment.c_content+
'</div><div class="c_item_date">'+comment.c_item_date+'</div><hr/></div>')
return c_item}
$('body').on('change','.postselect select',function(){console.info(this)
self=$(this)
ul=self.parents('.ui-page').find('ul')
ul.find('li').show()
var label=this.value
if(this.value!='all'){ul.find('li.padsmall:not([data-bak-label='+label+'])').hide();}
ul.find('li.ui-li-divider').each(function(){var divider=$(this)
var i=0
divider.nextUntil('li.ui-li-divider').each(function(){if($(this).attr('style')!='display: none;'){i++;}})
if(i==0){divider.hide();}
else{divider.children('span.ui-li-count').text(i)}})
ul.listview('refresh');})
openPhotoswipe=function(element,self_url){pswpElement=$('.pswp')[0]
var items=[],urls=[]
element.find('img.decimgsrc').each(function(){var self=$(this)
item={src:self.attr('src'),w:parseInt(self.attr('img-size').split('x')[0]),h:parseInt(self.attr('img-size').split('x')[1]),title:self.prev().text()}
items.push(item)
urls.push(self.attr('src'))})
i=urls.indexOf(self_url)
console.info(items)
var options={history:false,focus:false,index:i,showAnimationDuration:0,hideAnimationDuration:0}
var gallery=new PhotoSwipe(pswpElement,PhotoSwipeUI_Default,items,options)
gallery.init();}
$(document).on('click','img.decimgsrc',function(){var self=$(this)
var page=self.parents('.ui-page')
console.info(page)
if(UA.search('MicroMessenger/6')!=-1&&wxready&&page[0].hasAttribute('wechatsignused')){openPhotoPreviewsInWx(page,self.attr('src'))
$.post('manage?action=photoswipe_inwx');}else{openPhotoswipe(page,self.attr('src'))
$.post('manage?action=photoswipe');}})
openPhotoPreviewsInWx=function(page,self_url){wx.previewImage({current:self_url,urls:page.find('img.decimgsrc').map(function(){return this.src}).get()});}
$('<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true"><div class="pswp__bg"></div><div class="pswp__scroll-wrap"><div class="pswp__container"><div class="pswp__item"></div><div class="pswp__item"></div><div class="pswp__item"></div></div><div class="pswp__ui pswp__ui--hidden"><div class="pswp__top-bar"><div class="pswp__counter"></div><button class="pswp__button pswp__button--close" title="Close (Esc)"></button><button class="pswp__button pswp__button--share" title="Share"></button><button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button><button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button><div class="pswp__preloader"><div class="pswp__preloader__icn"><div class="pswp__preloader__cut"><div class="pswp__preloader__donut"></div></div></div></div></div><div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap"><div class="pswp__share-tooltip"></div></div><button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button><button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button><div class="pswp__caption"><div class="pswp__caption__center"></div></div></div></div></div>').appendTo('body')
$(document).on('click','a#mapapplypost',function(){$.mobile.loading('show')
var self=$(this)
form=self.parents('form')
if(form.find(':file')[0].files.length==1&&form.find(':file')[0].files[0].size>1024*1024){mymessage('上传文件超过1MB,请重新选择')
return false}
if(form.find(':file')[0].files.length!=1){mymessage('请选择一张图片后再上传')
return false}
self.addClass('ui-disabled')
postdata=new FormData(form[0])
$.ajax({url:'manage?action=mapapply',type:'POST',data:postdata,contentType:false,processData:false}).done(function(data){console.info(data)
if(data=='done'){mymessage('申请提交成功,请等候审核')
location.href="sellmap"}else if(data=='notimage'){mymessage('您上传的文件不是图片文件,请重新选择图片上传')
self.removeClass('ui-disabled')}else{mymessage('未知错误:'+data)
self.removeClass('ui-disabled')}})})
$(document).on('change','#map input#file',function(){console.info(this)
if(this.files&&this.files[0]){if(this.files[0].size>1024*1024){mymessage('上传文件超过1MB,请重新选择')}else{$('#map div.imgpre img').attr('src',URL.createObjectURL(this.files[0]))}}})
$(document).on('pageshow','section#map, section#fwquery',function(){$.mobile.loading('show')})
$(document).on('click','.share a.nosession',function(){mymessage('请先登录,再进行分享')
return false;})
$(document).on('click','.qr_display',function(){var self=$(this)
var page=self.parents('.ui-page')
page.find('.popupqr').popup('open')})
var fwcode
$(document).on('click','#fwbutton',function(){$.mobile.loading('show',{textVisible:true,text:'防伪码查询中...'})
$('#fwtojfbutton').hide()
var self=$(this)
self.addClass('ui-disabled')
var code=$('#fwcode').val().replace(/-/g,'')
if(code.length!=16){mymessage('您输入的防伪码位数不对,请查看清楚后重新输入')
$('#fwcode').focus()
return false;}
if(code.search(/[^\d]/)!=-1){mymessage('您输入的防伪码存在字母,请查看清楚后重新输入')
$('#fwcode').select()
return false;}
$.post('manage?action=fwquery&code='+code,null,null,'json').done(function(data){$.mobile.loading('hide')
self.removeClass('ui-disabled').find('.ui-btn-text').text('重新查询')
var text=data.msg
$('#fwresult').html(text).slideDown()}).fail(function(data){self.removeClass('ui-disabled').find('.ui-btn-text').text('重新查询')
mymessage('未知错误')})})
$(document).on('click','#downapp a[data-icon="android"], #downapp a[data-icon="apple"]',function(){var action=$(this).attr('data-icon')
if(inwx){if(UA.match(/Mac\s+OS/i)){if(action=='android'){var winHeight=$(window).height();$(".weixin-tip").css("height",winHeight);$(".weixin-tip").show();$.post('manage?action=downapp_inwx_appledownanroid_faild')
return false;}else{$.post('manage?action=downapp_inwx_success_to_applewebsite')
location.href="https://itunes.apple.com/cn/app/yin-su-feng-bao/id1043432800"
return false}}else if(action=='apple'){mymessage('抱歉,您无法在非iOS平台下载iOS版本App')
$.post('manage?action=downapp_inwx_androiddownapple_faild');return false;}
var winHeight=$(window).height();$(".weixin-tip2").css("height",winHeight);$(".weixin-tip2").show();$.post('manage?action=downapp_inwx_success_to_QQdown');return false}else{$.post('manage?action=downapp_success_'+action);}})
$(document).on('click','#popupAndroidDown a',function(){$.post('manage?action=downapp_sucessto_'+$(this).attr('appto'));})
$(document).on('click','.weixin-tip,.weixin-tip2',function(){$(this).hide();})
$(document).on('click','#fwscan',function(){wx.scanQRCode({needResult:1,scanType:["qrCode"],success:fwscansucfunc});})
fwscansucfunc=function(res){var result=res.resultStr;var codes=result.split('http://wap.xologood-fc.com/yingbaozhineng/fw.html?code=')
if(codes.length!=2){mymessage('抱歉,您所扫描的不是音速风暴的防伪二维码,请重新扫描')}else{var code=codes[1]
var newfwvalue=''
var i
for(i=0;i<3;i++){newfwvalue+=code.slice(i*4,i*4+4)+'-'}
newfwvalue+=code.slice(i*4,i*4+4)
$('#fwcode').val(newfwvalue)}}
$(document).on('click','.sharewx a',function(){$('.weixin-tip2').show()})
$(document).on('change','.selectlanguege select',function(){console.info(this.value)
if(this.value==""||this.value=="/en/")
location.href=location.origin+this.value})
$('body').on('pageshow','#feature.ui-page',function(){$('#feature a.ui-collapsible-heading-toggle').bind('click',function(){$('body').scrollTop(0);})})
$('body').on('pagehide','#feature.ui-page',function(){$('#feature a.ui-collapsible-heading-toggle').unbind('click');})